<template>
	<view class="newworkOrder_container">
		<view class="" style="height: 160rpx;">
			<view class="mail_List fixed z_ninetynine">
				<view class="mail" style="font-weight: 700;">
					<view class="order" v-if="current==1">报事详情</view>
					<view class="order" v-if="current==2">建立工单</view>
				</view>
			</view>
			<view class="icon fixed z_ninetynine">
				<u-icon name="arrow-left" color="#fefefe" size="40" @click="navigateBack"></u-icon>
			</view>
		</view>
		<!-- 报事人信息 -->
		<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">报事人信息</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="报事人:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.repairName"
						:clearable="false" :disabled="true" />
				</u-form-item>
<!-- 				<u-form-item label="联系方式:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.repairName"
						:clearable="false" :disabled="true" />
				</u-form-item> -->
			</u-form>
		</view>
		<!-- 报事详情 -->
		<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">报事详情</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="标题:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.repairTitle"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="类型:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="园区报修"
						:clearable="false" :disabled="true" v-if="particulars.repairType==0" />
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="居家维修"
							:clearable="false" :disabled="true" v-if="particulars.repairType==1" />
							<u-input v-model="form.address"
								placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="灾害报事"
								:clearable="false" :disabled="true" v-if="particulars.repairType==2" />
								<u-input v-model="form.address"
									placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="投诉"
									:clearable="false" :disabled="true" v-if="particulars.repairType==3" />
									<u-input v-model="form.address"
										placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="建议"
										:clearable="false" :disabled="true" v-if="particulars.repairType==4" />
				</u-form-item>
				<u-form-item label="状态:" v-if="current==1">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.auditFlag=='0'? '未审核' : item.auditFlag=='1' ? '同意' : '拒绝'"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="报事时间:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.createTime" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="事件地址:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.communityAddress"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="事件描述:" label-position="top">
					<u-input v-model="form.describe" type="textarea"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.description" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item v-show="image.length!=0">
					<view style="display: flex; flex-wrap: wrap;">
						<view style="width:210rpx; height: 316rpx;margin-right: 10rpx;margin-bottom: 10rpx; background-color: #f2f2f2;" v-for="(item,index) in image">
							<image :src="item.imgUrl" mode="" style="width: 100%;height: 100%;"></image>
						</view>
<!-- 						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view> -->
					</view>
				</u-form-item>
			</u-form>
		</view>
		<!-- 工单分配 -->
		<view class="order_Allocation" v-if="current==2">
			<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
				<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
					style="font-weight: 700; font-size: 30rpx;">工单分配</text>
			</view>
			<view class="card" style="padding: 0 42rpx;">
				<u-form :model="form" ref="uForm" >
<!-- 					<u-form-item label="选择负责人:">
						<u-input v-model="form.Reporter"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="刘备"
							:clearable="false" :disabled="true" />
					</u-form-item> -->
					<u-form-item label="选择执行人:">
<!-- 						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="黄忠、马超"
							:clearable="false" :disabled="true" /> -->
							<u-input v-model="form.title" :disabled="true" :type="newList==''? 'select' : 'text'"
								:select-open="show" placeholder-style="color: #cccccc; text-align: right;"
								:placeholder="newList==''? '请选择执行人': newList" @click="show = true" />
					</u-form-item>
<!-- 					<u-form-item label="维保时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 12: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item>-->
					<view class="li">
						<text>结束时间</text>
						<view class="flex1">
							<picker mode="date" :value="start_date" :start="start_date" @change="bindDateChange2">
								<view class="date">{{other}}</view>
							</picker>
						</view>
					</view>
<!-- 					<u-form-item label="结束时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 24: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item> -->
				</u-form>
				<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
				<!-- 				<uni-card class="second_card" style="margin: 0;">
					<u-cell-group :border="false">
						<u-cell-item :arrow="false" hover-class="none" title="选择负责人:" value="刘备"></u-cell-item>
						<u-cell-item :arrow="false" hover-class="none" title="选择执行人:" value="黄忠、马超"></u-cell-item>
						<u-cell-item :arrow="false" hover-class="none" title="维保时间:" value="2021-06-09 12: 23: 32">
						</u-cell-item>
						<u-cell-item :arrow="false" hover-class="none" title="结束时间:" value="2021-06-09 24: 23: 32">
						</u-cell-item>
					</u-cell-group>
				</uni-card> -->
			</view>
		</view>
		<view class="button" v-if="current==1">
			<u-button type="primary" style="flex: 1;" @click="resolved(repairId)">已解决</u-button>
			<u-button type="success" style="flex: 1;" @click="Approved">审核通过</u-button>
		</view>
		<view class="button" v-if="current==2">
			<u-button type="primary" style="flex: 1;" @click="cancel">取消</u-button>
			<u-button type="success" style="flex: 1;" @click="determine">确定</u-button>
		</view>
		<u-popup v-model="show2" mode="center" width="626rpx" height="430rpx" border-radius="20">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				工单提示</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">工单发布成功</view>
			</view>
		</u-popup>
		<!-- 弹框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				// form表单
				form: {
					Reporter: '',
					title: '',
					address: '',
					describe: '',
					chargePerson: '',
					Executor: '',
					Maintenance: '',
					end: '',
					// 手机号码
					staffPhone:''
				},
				// 演示地址，请勿直接使用
				action: 'http://www.example.com/upload',
				button_flag: true,
				buttontwo_flag: false,
				current: 1,
				show: false,
				newList: '',
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				// 待审核Id
				repairId:'',
				// 车辆详情
				particulars:'',
				image:'',
				// 审核通过
				staff:'',
				start_date: currentDate,
				end_date: currentDate,
				other: '请选择结束时间',
			}
		},
		onLoad(val) {
			this.loginId = uni.getStorageSync("setModel")
			if(val.repairId){
			this.repairId=val.repairId
				this.getListVehicleByIds()
			}
			// this.loading()
		},
		methods: {
			bindDateChange2: function(e) {
				this.end_date = e.target.value;
				this.other = this.end_date;
			},
			// 获取当前时间
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
			
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			// 点击已解决
			resolved(repairId) {
				// 通过id删除报事保修待审核状态列表详情
				// uni.navigateBack()
				const self =this
				this.$http.put('WorkOrder/deleteWarrantByAudit',{id:this.repairId}).then(res => {
				console.log(222)
							self.$refs.uToast.show({
								title: '已解决',
							})
							// uni.navigateBack()
							setTimeout(function() {
								uni.switchTab({
								    url: '/pages/work_order/work_order'
								});
							}, 1000);
				})
			},
			// 点击审核通过
			Approved() {
				this.current = 2
				// 待审核列表详情审核通过
				this.$http.put('WorkOrder/updateAuditPassed',{repairId:this.repairId,}).then(res => {
					console.log(res)
				})
				// 选择审核通过后列表中的 执行人
				this.$http.get('WorkOrder/getStaff',{
					deptId:this.loginId.deptId
				}).then(res => {
					let lists = res.data
					this.list= this.changeKey (lists, ['value', 'label','staffPhone']);
					console.log(res,this.list, '审核通过') 
					// this.owners = res.data
				})
			},
			cancel() {
				this.current = 1
			},
			// 点击确定触发
			determine() {
				this.show2 = true
				
				if(this.form.title=='') {
					this.$refs.uToast.show({
						title: '请选择执行人',
					})
				} else {
					this.$http.post('WorkOrder/insertWordOrder',{
						loginId:this.loginId.userId,
						repairId:this.repairId,
						time:this.other,
						phone:this.form.staffPhone
					}).then(res => {
						// this.particulars=res.data
						console.log(res, '提交')
						// this.owners = res.data
					})
					// console.log(171)
					setTimeout(function() {
						uni.navigateBack()
					}, 1000);
					
				}
				
			},
			// 访客详情信息
			getListVehicleByIds() {
				this.$http.get('WorkOrder/AuditDetails',{repairId:this.repairId,loginId:this.loginId.userId}).then(res => {
					this.particulars=res.data
					this.image=res.data.image
					console.log(res, '待审核')
					// this.owners = res.data
				})
			},
			// 注意返回值为一个数组，单列时取数组的第一个元素即可(只有一个元素)
			confirm(e) {
				// console.log(e);
				let sign = ''
				e.forEach((item,index) => {
					this.sign =item.value
					this.form.title=item.label
						// console.log(item.label);
						// console.log(this.sign);
				   })
				this.list.forEach((item,index)=>{
					if(item.value==this.sign) {
						console.log(item.staffPhone)
						this.form.staffPhone=item.staffPhone
					}
				})
				// console.log(e-'1')
				// let abc = this.list[e-'1'].staffPhone
				// console.log(abc)
			},
			changeKey (lists, key) {
			            let newArr = [];
			            lists.forEach((item) => {
			                let newObj = {};
			                for (var i = 0; i < key.length; i++) {
			                newObj[key[i]] = item[Object.keys(item)[i]]
			                }
			                newArr.push(newObj);
			            })
			                return newArr;
		   }
		}
	}
</script>

<style lang="scss" scoped>
	.newworkOrder_container {
		.mail_List {
			overflow: hidden;
			width: 100%;
			background-color: #f2f2f2;

			.mail {
				padding: 10rpx 0;
				// margin-top: 96rpx;
				color: #999999;
				font-size: 40rpx;
				background-color: #e5e5e5;
			}

			.order {
				text-align: center;
			}
		}

		/deep/.card {
			.u-form-item--left {
				flex: unset !important;
				width: unset !important;
			}
		}
		
		.order_Allocation {
			/deep/.card {
				u-form-item {
					.u-input {
						input {
							text-align: right!important;
						}
						
					}
				}	
				.li {
					display: flex;
					align-items: center;
					border-bottom: 1px solid #efefef;
				
					 text {
						padding: 40rpx 0;
						font-size: 34rpx;
						font-family: '黑体';
					}
				
					 .flex1 {
						flex: 1;
						text-align: right;
						padding-right: 25rpx;
						color: #999999;
						font-size: 32rpx;
					}
				
				}
			}
		}

		.icon {
			position: absolute;
			top: 18rpx;
			// top: 114rpx;
			left: 20rpx;
		}

		.second_card {
			.u-cell {
				padding: 18rpx 32rpx;

				/deep/.u-cell__value {
					color: #333333;
					font-weight: 600;
				}
			}

			/deep/.uni-card__content {
				padding: 16rpx 24rpx;
			}
		}

		/deep/button {
			border-radius: unset !important;
		}

		.uni-border[data-v-19622063]:after {
			border: unset;
		}

		/deep/.uni-border.data-v-19622063:after {
			border: unset;
		}

		.slot-btn__hover {
			background-color: rgb(235, 236, 238);
		}

		.button {
			display: flex;
			// position: fixed;
			// left: 0;
			// right: 0;
			// bottom: 0;
			margin-top: 200rpx;
			border-radius: 14rpx;
			overflow: hidden;
			z-index: 9;

			.u-btn {
				border-radius: unset;
			}
		}
		.work_Order {
			margin-top: 60rpx;
			text-align: center;
			.work_Order_top {
				width: 168rpx;
				height: 168rpx;
				margin: 0 auto;
				background-color: #e5e5e5;
				border-radius: 50%;
			}
		}
	}
</style>
